perm filename PNTAID.PAL[PNT,HE] blob sn#466801 filedate 1979-08-11 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00005 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	  FILES, SETNAM
C00004 00003	  Data structures:  Note cells, message buffers
C00007 00004		server,srvsts,pntexecute
C00010 00005	ALINIT:
C00014 ENDMK
C⊗;
;  FILES, SETNAM


.IFNDF ALAID
    DEBUG == 1
.IFF
    DEBUG == 0
.ENDC

KERNEL == 1
FLOAT == 1

.IFNZ DEBUG

;Set up the necessary mapping for the Zonker
	.INSRT ZONKER.PAL[AL,HE]

.OFFSET -160000		;Put ALAID in the Zonker

    .IF1
        .TITLE  Test of ALAID
        .INSRT ALHEAD.PAL[AL,HE]
        .INSRT K1DEF.PAL[11,SYS]
    .ENDC

. = PATCH
	.BLKW 200	;Patch area

	;If DDT sends us to user I space this will start the Kernel up anyway
. = START
	RESTRT		;EMT gets us into Kernel I space
	RESTRT
	RESTRT		;Kernel INIT entry point

. = INTRP

CODE$ == .		;Interpreter code & data spaces start here
DATA$ == .

    .INSRT ALIO.PAL[AL,HE]
    .INSRT FLOAT.PAL[AL,HE]
	STSW  LBDEBUG,1	;1 => first word of any large block is address of maker.
    .INSRT LARGEB.PAL[AL,HE]
    INSTSZ == 20    ;Size of an interpreter stack
.ENDC


.IFZ DEBUG
CODE
;  Special pseudo-ops

SETNAM:	;Interpreter code
	MOV @IPC(R4),INTNAM(R4)
	BMPIPC		;
	CCC		;Clear Condition Code
	RTS PC		;Done
.ENDC
;  Data structures:  Note cells, message buffers

;  Notes from 10 to 11:
WAKEUP == 0
LISTEN == 1
WORK   == 2
GOSLEEP == 3

;  Notes from 11 to 10:
ASLEEP == WAKEUP
AWAKE  == 100
LISTNING == 101
WORKING == 102
DONEWORKING == 103
RESTING == 103

;NOTB10  The notebox from 11 to the 10 (byte address) defined in COMTAB
;NOTB11  The notebox from 10 to the 11 (byte address) defined in COMTAB


DATA
RETSTK==FPPTR
PBUFFSIZ == 1000	;1000 words of pcode
IBUFFSIZ == 1000	;1000 words of integer
FBUFFSIZ == 2000	;1000 words of fp numbers
IIII == .
.==NOTB11
	.WORD 0
PCDBUF::.WORD 0		;pcode buffer address
INTBUF::.WORD 0		;integer buffer starting address
FPBUF:: .WORD 0		;floating point buffer starting address
INTPTR::.WORD 0		;current position of integer pointer
FPPTR::	.WORD 0		;current position of fp buffer
INTSIZ::.WORD 0		;size of integer buffer
FPSIZ::	.WORD 0		;size of fp buffer
.==IIII

CURNAM:	.WORD 0	;The current ISB for active interpreter.
PNTNAM:	.WORD 0 ;The current ISB for pointy process
ALLIVE:	.WORD 0	;AL interpreter alive if non-zero

STATUS:	.WORD 0	;current status of POINTY in 11

;  Interlock event
ALDEVT:	.WORD 0

;HN  Halt Switch
HALTSW:	.WORD 0		;HN	  0 = Run  ,   1 = Halt

;	server,srvsts,pntexecute

CODE
PNTEXECUTE:
COMMENT	⊗ initializes the buffers and executes the pcode
	⊗

	MOV INTBUF,INTPTR	; beginning of integer buffer
	MOV FPBUF,FPPTR		; beginning of fp buffer
	MOV PNTNAM,R4		; get the right interpreter
	MOV PCDBUF,IPC(R4)	; beginning of pcode buffer
	MOV CURNAM,R0
	MOV ENV(R0),ENV(R4)
	MOV LEV(R0),LEV(R4)
	JSR PC,NOTICE		; make sure read arm if necessary
;****
	MOV RF,-(SP)		; Save RF
	MOV SP,RF
	JSR PC,INTRP0		; go do the interpreting
;****				; we will return here only from pdone
	MOV INTPTR,INTSIZ	; compute the integer buffer size
	SUB INTBUF,INTSIZ
	ASR INTSIZ
	MOV FPPTR,FPSIZ		; compute the fp buffer size
	SUB FPBUF,FPSIZ		; by getting difference and dividing by 4
	ASR FPSIZ
	ASR FPSIZ
	RTS PC

;	routine to let 10 know we are awake
DATA
STPDB:	PDBLK	3,100,F	; set up pbd for process to tell 10 we are alive
CODE

SRVSTS:	MOV STATUS,NOTB11
	TST ALDONE
	BEQ 1$
	DISMIS
1$:	SLEEP	#4
	BR SRVSTS

DATA
ALPDB:	PDBLK 2,150,F	;Makes a process descriptor for server
NOTVL:	0
CODE

SERVER:	MOV NOTB10,NOTVL ;get value of notb10
	CMP NOTVL,#LISTEN	;is he telling us to listen
	BNE 1$
	MOV #LISTNING,STATUS	;say we are ready to listen
	MOV STATUS,NOTB11
	BR  10$
1$:	CMP NOTVL,#WORK		;is he telling us to work?
	BNE 2$
	MOV #WORKING,STATUS
	MOV STATUS,NOTB11	;we will tell him we are working
	JSR PC,PNTEXECUTE	;action
	MOV #DONEWORKING,STATUS ;finished working, tell him that
	MOV STATUS,NOTB11
	BR  10$
2$:	CMP NOTVL,#GOSLEEP	;is he telling us he doesnt need us anymore
	BNE 3$
	MOV #AWAKE,STATUS	;tell him we are available
	MOV STATUS,NOTB11
10$:
3$:	CLR NOTB10
	TST ALDONE		;TEST IF AL PROGRAM FINISHED
	BEQ 4$
	DISMIS			;yes, AL program is done, go away
4$:	SLEEP #500		;rest for a little while
	BR  SERVER		;go find out if there is any more mail
ALINIT:
COMMENT	⊗ initialize every thing ⊗
	MOV #PNTDAT,R0		;put in beginning of pointy buffer space
	MOV R0,INTBUF		;store starting address as buffer of integers
	ADD #IBUFFSIZ*2,R0	;get appropriate byte offset for next buffer
	MOV R0,FPBUF		;this is starting address of FP buffer
	ADD #FBUFFSIZ*4,R0	;get a buffer for floating point numbers
	MOV R0,PCDBUF		; this is starting address for pcode buffer
	MOV #AWAKE,STATUS	;tell 10 we are awake
	SCHEDU #STPDB,#SRVSTS,#USRDM,#2	;schedule srvsts
; now let us create the ISB for the POINTY process
	EVMAK			;Create and signal once the AL interlock event.
	MOV (SP),ALDEVT
	EVSIG
;	CLR WAITQ+QNEXT
	CLR NOTB11
	CLR NOTB10
	MOV #1,ALLIVE		;Indicate that the AL interpreter is alive
	MOV #ISBS,R0		;R0 ← Size (in words) of an interpreter status block
	JSR PC,GTFREE		;R0 ← LOC[new interpreter status block]
;	EVMAK			;-(SP) ← event for EVT in this interpreter
;	MOV (SP),EVT(R0)	;new EVT ← event just created.
	MOV R0,-(SP)		;Save LOC[new interpreter status block]
	MOV #INSTSZ,R0		;R0 ← Size needed for an interpreter stack
	JSR PC,GTFREE		;R0 ← LOC[new interpreter stack]
	MOV (SP)+,R1		;R1 ← LOC[new interpreter status block]
	MOV R0,STKBAS(R1)	;Store away new stack base
	ADD #2*INSTSZ,R0	;R0 ← LOC[top of new stack] (INSTSZ is in bytes)
	MOV #ALPDB,R2		;R2 ← LOC[ALAID process descriptor]
	BIS #UGRSAV+USKSAV,PDBSTA(R2)	;Use saved registers so we can set things up
	MOV R0,PDBR3(R2)	;Store away new interp stack pointer (reg 3)
	MOV R2,PDB(R1)		;Store away LOC[PDB] in new ISB
	MOV R1,PDBR4(R2)	;Store away LOC[ISB] in reg 4 of PDB
	MOV USKMAX(R2),USKP(R2)	;Make sure we have a good stack pointer
	MOV R1,PNTNAM	;This is the current interpreter
	EVWAIT INTEVT		;Interlock sensitive operation, GC needs this
	MOV #NXTINT+ISTBLK,R0	;Link into the interpreter list.
	MOV (R0),NXTINT(R1)
	MOV R1,(R0)
	EVSIG INTEVT		;End of interlock
	SCHEDU R2,#SERVER,#USRDM,#2 ;Cause the new process to be started, suspended
	RTS PC

ALKILL:	CLR ALLIVE		;Indicate that the AL interpreter is dead
	RTS PC